Page({

  data: {
    list: [{ n: 3 }, { n: 4 }, { n: 5 }],
    activeIndex: 0,
  },

  onLoad() {
    let { list } = this.data
    if (list.length < 3) {
      wx.showToast({
        title: '初始数量不能少于3个',
        icon: 'none'
      })
    }
  },

  onChange(e) {
    let { current } = e.detail
    let { activeIndex, list } = this.data
    let length = list.length
    if (length >= 3) {
      // 下一个
      if ((activeIndex < current) && (activeIndex !== 0 || current !== length - 1) || (activeIndex === length - 1 && current === 0)) {
        list[(current + 1) % length].n = list[current].n + 1
      }
      // 上一个
      else {
        let index = current
        index--
        if (current - 1 < 0) {
          index = length - 1
        }
        list[index].n = list[current].n + -1
      }
      this.setData({
        activeIndex: current,
        list,
      })
    }
  }

})